Prior and Posterior Predictive Check

In this notebook, we will examine the prior and posterior predictive distributions. This will tell us how well defined our priors are and whether or not they can capture some given data. In addition, we will look at the posterior predictive distribution, to see how well samples from our posterior capture our data after optimisation.

Environment

Make sure the environment is correct and print for posterity.

Setting Up Model

The second step of the modelling process will be to define the ODE model. For network diffusion, this is given by:

$$ \frac{d\mathbf{u}}{dt} = -\rho \mathbf{L} \mathbf{u} $$

We can set this up as a julia function as follows:

Inference

Now that we have the model, we wish to infer the values from some synthetic data. In this case, we will use points generated with the ODE integrator plus some Gaussian noise.

$$ \mathbf{y} = f(\mathbf{u0}, \rho) + \mathcal{N}(0, \sigma) $$$$ \sigma = 0.02 $$

Let's do this and plot the data.

Generative Model

Next, we can define a generate model to fit this data. We use the following priors.

$$\sigma \approx \Gamma^{-1}(2, 3)$$

$$\rho \approx \mathcal{N}(5,10,[0,10])$$ $$\mathbf{u0} \approx \mathcal{N}(0,2,[0,1])$$

Prior Predictive Model

We can sample directly from the prior distributions and generate data using these values. The results of this will be that can visualise the simulation space of our generative model. It's important for our simulation that we are able to generate samples that can reproduce the data. We should be able to see this from the prior predictive model.

Posterior Predictive Model

Now that we have sampled from the posterior using the NUTS sampler, we can use some of these samples to run simulations and plot the posterior predictive model, similarly as we did for the prior predictive model.

The results show that the posterior distribution has converged well to capture the data for each node time series.

Prior predictive for N = 50

Next, we'll run the same process for a network of size N = 50.

Plotted above is the time series for a single node (blue), data points (pink) and simulations from the prior (grey). Conversely to our prior predictive model for five nodes, the dynamics here show the model reaches equillibium much faster and almost invariably of starting concentration. Thus, for most data points, i.e. after equillibium, the prior captures the data reasonably well. If one images what the posterior should look like for the equillibium data, it would closely resemble the prior. This lends credence to the idea that the likelihood landscape for this particular data is somewhat flat, since, intuitively, one knows that a flat likelihood means the prior and posterior will be similar, if not the same.